package elementos;

import mapControl.GraphicsMapControl;

import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.image.Texture.MagnificationFilter;
import com.jme.image.Texture.MinificationFilter;
import com.jme.image.Texture.WrapMode;
import com.jme.math.Vector3f;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Box;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jmex.physics.PhysicsNode;


public class Floor {

	PhysicsNode nodo;
	public Floor(String name, GraphicsMapControl mapControl) {
		
		this.nodo = mapControl.getPhysicsSpace().createStaticNode();

		

		TextureState ts = mapControl.getDisplay().getRenderer().createTextureState();
		Texture t = TextureManager.loadTexture(getClass().getClassLoader()
				.getResource("data/texturas/floor_texture.jpg"),
				MinificationFilter.NearestNeighborLinearMipMap,
				MagnificationFilter.NearestNeighbor);
		t.setWrap(WrapMode.Repeat);
		ts.setTexture(t);
		
		Spatial box = new Box("floor", new Vector3f((mapControl.getTilesize()
				* mapControl.getWide() / 2), -0.1f, (mapControl.getTilesize()
				* mapControl.getHight() / 2)), mapControl.getTilesize()
				* mapControl.getWide() / 2, 0.1f, mapControl.getTilesize()
				* mapControl.getHight() / 2);

		box.setModelBound(new BoundingBox());
		box.updateModelBound();

		box.setRenderState(ts);
		nodo.attachChild(box);
		nodo.generatePhysicsGeometry();

		mapControl.getRootNode().attachChild(nodo);
		mapControl.getRootNode().updateGeometricState(0, true);
	}

	public PhysicsNode getNodo() {
		return nodo;
	}


}
